<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>9_收集表单数据</title>
</head>

<body>
    <div id="main"></div>

    <!-- 引入react核心库，引入对象：React -->
    <script src="./js/react.development.js"></script>
    <!-- 引入react-dom，用于支持react操作DOM，引入对象：ReactDOM -->
    <script src="./js/react-dom.development.js"></script>
    <!-- 引入babel，用于将jsx转为js -->
    <script src="./js/babel.min.js"></script>
    <!-- 引入对组件属性约束，引入对象：PropTypes -->
    <script src="./js/prop-types.js"></script>

    <script type="text/babel">
        /* 
            高阶函数：
                1. 接收参数是一个函数
                2. 调用后的返回值是个函数
        */


        class Box extends React.Component {

            // 初始化状态
            state = {
                username: '',
                password: ''
            }

            // 柯里化
            saveFormData = (dataType) => {
                return (event) => {
                    this.setState({
                        [dataType]: event.target.value
                    })
                }
            }

            // 非柯里化
            saveFormData2 = (dataType, event) => {
                this.setState({
                    [dataType]: event.target.value
                })
            }

            handlerSubmit = (event) => {
                event.preventDefault()
                const { username, password } = this.state
            }

            render() {
                return (
                    <form action="http://127.0.0.1:5500" onSubmit={this.handlerSubmit}>
                        <label>用户：</label>
                        <input onChange={this.saveFormData('username')} type="text" name="username" /><br />
                        <label>密码：</label>
                        <input onChange={event => this.saveFormData2('password', event)} type="text" name="password" /><br />
                        <button>login</button>
                    </form>
                )
            }
        }

        ReactDOM.render(<Box />, document.getElementById('main'))

        function sum(a) {
            return (b) => {

            }
        }
    </script>
</body>

</html>